package cn.hg.jbsa.generator;

import com.jfinal.kit.PathKit;

import io.jboot.app.JbootApplication;
import io.jboot.codegen.model.JbootBaseModelGenerator;
import io.jboot.codegen.model.JbootModelGenerator;
import io.jboot.codegen.service.JbootServiceImplGenerator;
import io.jboot.codegen.service.JbootServiceInterfaceGenerator;

/**
 * @author golly
 * @date 2021/09/30
 */
public class _JbsaAdminModelGenerator {

    /**
     * @param args
     */
    public static void main(String[] args) {
        //配置数据量的连接信息，可以通过 JbootApplication.setBootArg 来配置
        //也可以在 jboot.properties 里配置
        JbootApplication.setBootArg("jboot.datasource.url", "jdbc:mysql://localhost/hg_jbsa?serverTimezone=GMT%2B8&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useUnicode=true");
        JbootApplication.setBootArg("jboot.datasource.user", "root");
        JbootApplication.setBootArg("jboot.datasource.password", "123456");


        String modelPackage = "cn.hg.jbsa.admin.model"; //生成的Model的包名
        String baseModelPackage = "cn.hg.jbsa.admin.model.base"; //生成的BaseModel的包名

        String entityPath = PathKit.getRootClassPath() + "/../../../../jbsa-admin/jbsa-admin-model";

        //Model存放的路径，一般情况下是 /src/main/java 下，如下是放在 test 目录下
        String modelDir = entityPath + "/src/main/java/" + modelPackage.replace(".", "/");
        String baseModelDir = entityPath + "/src/main/java/" + baseModelPackage.replace(".", "/");

        System.out.println("start generate...");
        System.out.println("generate dir:" + modelDir);

        //开始生成 Model 和 BaseModel 的代码
        new JbootBaseModelGenerator(baseModelPackage, baseModelDir)
        .setGenerateRemarks(true)
        //.setRemovedTableNamePrefixes("jbsa_")
        .generate();

        JbootModelGenerator modelGenerator = new JbootModelGenerator(modelPackage, baseModelPackage, modelDir);
        //modelGenerator.setRemovedTableNamePrefixes("jbsa_");
        modelGenerator.setGenerateDaoInModel(true);
        modelGenerator.generate();


        String servicePackage = "cn.hg.jbsa.admin.service"; // service 层的接口包名
        String serviceImplPackage = "cn.hg.jbsa.admin.provider"; // service 层的接口实现类包名


        // 设置 api 层和 provider 层代码的存放目录
        String apiPath = PathKit.getRootClassPath() + "/../../../../jbsa-admin/jbsa-admin-service";
        String providerPath = PathKit.getRootClassPath() + "/../../../../jbsa-admin/jbsa-admin-provider";


        // 设置 api 层和 provider 层代码的存放目录
        String apiOutputDir = apiPath + "/src/main/java/" + servicePackage.replace(".", "/");
        String providerImplOutputDir = providerPath + "/src/main/java/" + serviceImplPackage.replace(".", "/");


        //开始生成代码
        new JbootServiceInterfaceGenerator(servicePackage, apiOutputDir, modelPackage)
        //.setRemovedTableNamePrefixes("jbsa_")
        .generate();
        new JbootServiceImplGenerator(servicePackage, serviceImplPackage, providerImplOutputDir, modelPackage)
        .setImplName("provider")
        .setGenerateRemarks(true)
        //.setRemovedTableNamePrefixes("jbsa_")
        .generate();

        System.out.println("end generated");
    }

}
